<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
       
       //定义一些页面变量
       $page_size=1;
       $max_page=4;
       $max_rows=1;
       $page=$_GET['page'];//当前页数
       $total_pages=1;
       $page_show=5;//显示的页码数
       $page_offset=($page_show-1)/2;
       $page_start=1;//开始的页码
       
       $dots="...";
       //执行sql语句
       $p=D('Page');
       $result=$p->limit($page-1,$page_size)->select();
       $total_pages=ceil($p->count()/$page_size);//计算总页数
       $page_end=$total_pages;//结束的页码 
       if($result){
         var_dump($result);
       }
       if($total_pages>$page_show){
        if($page>$page_offset+1){
           $dots="...";
           $this->assign('dots',$dots);
        }
        if($page>$page_offset){
          $page_start=$page-$page_offset;
          $page_former=$page-$page_offset+1;
          $page_next=$total_pages>$page+$page_offset?$page+$page_offset-1:$total_pages-1;
          $page_end=$total_pages>$page+$page_offset?$page+$page_offset:$total_pages;
        }else{
          $page_start=1;
          $page_former=2;
          $page=$page_start+$page_offset;
          $page_next=$total_pages>$page_show?$page_show-1:$total_pages;
          $page_end=$total_pages>$page_show?$page_show:$total_pages;

        }
        if($page+$page_offset>$total_pages){
          $page_start=$page_start-($page+$page_offset-$page_end);
          $page_former=$page_start+1;
          $page=8;
          $page_next=$page_end-1;

        }
       }
       if($total_pages>$page_show&&$total_pages>$page+$page_offset)
       {
        $dot="...";
        $this->assign('dot',$dot);
       }
       
       $this->assign('page_former',$page_former);
       $this->assign('page_next',$page_next);
       $this->assign('id',$result[0]['id']);
       $this->assign('username',$result[0]['username']);
       $this->assign('page',$page);
       $this->assign('total_pages',$total_pages);
       $this->assign('page_start',$page_start);
       $this->assign('page_end',$page_end);
      
      $this->display();
    }
    public function show(){
        
    	$this->display();
    }
}